db5e9e0fc78e677ff4e2bd96a923c5589635a3b0,ejb3/src/main/java/org/jboss/as/ejb3/timerservice/schedule/CalendarBasedTimeout.java,CalendarBasedTimeout,computeNextHour,#Calendar#,384
Before Change
int currentHour = currentCal.get(Calendar.HOUR_OF_DAY);
// if the current hour is a match, then nothing else to
// do. Just return back the calendar
if (currentHour == nextHour) {
return currentCal;
}
Calendar nextCal = this.truncate(currentCal, Calendar.DATE);
// At this point, a suitable "next" hour has been identified.
// There can be 2 cases
// 1) The "next" hour is greater than the current hour : This
// implies that the next hour is within the "current" day.
// 2) The "next" hour is lesser than the current hour : This implies
// that the next hour is in the next day (i.e. current day needs to
// be advanced to next day).
// handle case#1
if (nextHour > currentHour) {
// set the chosen day of hour
nextCal.set(Calendar.HOUR_OF_DAY, nextHour);
// since we are moving to a different hour (as compared to the current hour),
// we should reset the second and minute appropriately, to their first possible
// values
nextCal.set(Calendar.SECOND, this.second.getFirst());
nextCal.set(Calendar.MINUTE, this.minute.getFirst());
return nextCal;
}
// case#2
if (nextHour < currentHour) {
// set the chosen hour
nextCal.set(Calendar.HOUR_OF_DAY, nextHour);
// since we are moving to a different hour (as compared to the current hour),
// we should reset the second and minute appropriately, to their first possible
// values
nextCal.set(Calendar.SECOND, this.second.getFirst());
nextCal.set(Calendar.MINUTE, this.minute.getFirst());
// advance to next day
nextCal.add(Calendar.DATE, 1);
After Change
private Calendar computeNextTime(Calendar nextCal) {
int currentSecond = nextCal.get(Calendar.SECOND);
int currentMinute = nextCal.get(Calendar.MINUTE);
int currentHour = nextCal.get(Calendar.HOUR_OF_DAY);
final int currentTimeInSeconds = currentHour*3600 + currentMinute*60 + currentSecond;
// compute next second
Integer nextSecond = this.second.getNextMatch(currentSecond);
if (nextSecond == null) {
return null;
}
// compute next minute
if (nextSecond < currentSecond) {
currentMinute++;
}
Integer nextMinute = this.minute.getNextMatch(currentMinute < 60 ? currentMinute : 0);
if (nextMinute == null) {
return null;
}